package com.dcy.workflow.controller;

import com.dcy.common.base.controller.DcyBaseController;
import com.dcy.common.model.PageModel;
import com.dcy.common.model.PageResult;
import com.dcy.common.model.R;
import com.dcy.workflow.service.ActProcessService;
import com.dcy.workflow.vo.in.ProcessDefinitionSearchInVO;
import com.dcy.workflow.vo.out.ProcessDefinitionListOutVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * @Author：dcy
 * @Description:
 * @Date: 2021/6/7 10:24
 */
@RequiredArgsConstructor
@Validated
@Slf4j
@RestController
@RequestMapping("/flow/process")
@Api(value = "ProcessController", tags = {"流程操作接口"})
public class ProcessController extends DcyBaseController {

    private final ActProcessService actProcessService;


    @ApiOperation(value = "获取流程定义列表")
    @GetMapping(value = "/page")
    public R<PageResult<ProcessDefinitionListOutVO>> getProcessDefinitionList(ProcessDefinitionSearchInVO processDefinitionSearchInVO, PageModel pageModel) {
        return success(actProcessService.processDefinitionPageList(processDefinitionSearchInVO, pageModel));
    }

    @ApiOperation(value = "删除部署的流程，级联删除流程实例")
    @ApiImplicitParam(name = "deploymentId", value = "流程部署id", dataType = "String", paramType = "query")
    @PostMapping(value = "/delete")
    public R<Boolean> delete(@NotBlank(message = "流程部署id不能为空") String deploymentId) {
        return success(actProcessService.deleteDeployment(deploymentId));
    }

    @ApiOperation(value = "删除流程实例")
    @ApiImplicitParam(name = "processInstanceId", value = "流程实例id", dataType = "String", paramType = "query")
    @PostMapping(value = "/deleteProcIns")
    public R<Boolean> deleteProcIns(@NotBlank(message = "流程实例id不能为空") String processInstanceId) {
        return success(actProcessService.deleteProcess(processInstanceId));
    }

    @ApiOperation(value = "挂起、激活流程实例")
    @ApiImplicitParam(name = "processDefinitionId", value = "流程定义id", dataType = "String", paramType = "query")
    @PostMapping(value = "/hangChange")
    public R<Boolean> hangChange(@NotBlank(message = "流程定义id不能为空") String processDefinitionId) {
        return success(actProcessService.hangChange(processDefinitionId));
    }
}

